<template>
  <div class="centerRight2" style="height: 530px;">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <i class="iconfont icon-vector" />
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">病害清单</span>
        </div>
      </div>
      <div class="d-flex mt-1 jc-center body-box">
        <a-table :dataSource="defects" :columns="columns" size="middle" :pagination="pagination" :loading="loading"
          @change="handlePageChange" :scroll="{ y: 360 }">
          <template #bodyCell="{ column, record }">
            <div @dblclick="handleDoubleClickRow(record)">
              <template v-if="column.key === 'snap_date'">
                <!-- @dblclick="handlePressRow(record)" -->
                <div class="date-cell" @click="handlePressRow(record)">
                  {{ record.snap_date }}
                </div>
              </template>
              <template v-else>
                <!-- @dblclick="handlePressRow(record)" -->
                <div class="date-cell" @click="handlePressRow(record)">
                  {{ record[column['dataIndex']] }}
                </div>
              </template>
            </div>
          </template>
        </a-table>
        <!-- <dv-scroll-board v-if="config.data.length > 1" class="dv-scr-board" :config="config" /> -->
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive } from 'vue'

interface Props {
  defects: any[]
  pagination: {}
  loading: boolean
}

const props = withDefaults(defineProps<Props>(), {

})

const emit = defineEmits(['clickDefectRow', "doubleClickDefectRow", "pageChange", "dbRowClick"])

const config = reactive({
  header: ['病害类型', '位置', '发现时间'],
  data: [],
  // data: [
  //   ['组件1', 'dev-1', "<span  class='colorGrass'>↑75%</span>"],
  //   ['组件2', 'dev-2', "<span  class='colorRed'>↓33%</span>"],
  //   ['组件3', 'dev-3', "<span  class='colorGrass'>↑100%</span>"],
  //   ['组件4', 'rea-1', "<span  class='colorGrass'>↑94%</span>"],
  //   ['组件5', 'rea-2', "<span  class='colorGrass'>↑95%</span>"],
  //   ['组件6', 'fix-2', "<span  class='colorGrass'>↑63%</span>"],
  //   ['组件7', 'fix-4', "<span  class='colorGrass'>↑84%</span>"],
  //   ['组件8', 'fix-7', "<span  class='colorRed'>↓46%</span>"],
  //   ['组件9', 'dev-2', "<span  class='colorRed'>↓13%</span>"],
  //   ['组件10', 'dev-9', "<span  class='colorGrass'>↑76%</span>"]
  // ],
  rowNum: 10, //表格行数
  headerHeight: 35,
  headerBGC: '#0f1325', //表头
  oddRowBGC: '#0f1325', //奇数行
  evenRowBGC: '#171c33', //偶数行
  // index: true,
  columnWidth: [100, 200, 130],
  align: ['center']
})


const columns = [
  {
    title: '病害类型',
    dataIndex: 'defectType',
    key: 'defectType',
  },
  {
    title: '位置',
    dataIndex: 'route',
    key: 'route',
  },
  {
    title: '采集时间',
    dataIndex: 'snapDate',
    key: 'snapDate',
  },
];

const formatDate = (dateString) => {
  const date = new Date(dateString);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
}

const handlePressRow = (row: any) => {
  // console.log('handlePressRow ', row)

  emit('clickDefectRow', { 'extra': row })
}


const handleDoubleClickRow = (row: any) => {
  // console.log('doubleClickDefectRow ', row)

  emit('doubleClickDefectRow', { 'extra': row })

}

const handlePageChange = (pagination) => {
  // console.log("pagination ==>", pagination)
  emit('pageChange', pagination)
}


// const rowClick = (record, index) => {
//   // console.log('rowClick ', record, index)
//   return {
//     on: {
//       click: () => {
//         console.log('rowClick ', record, index)
//       }
//     }
//   }
// }

onMounted(() => {
  // console.log("props.defects ==>", props.defects)

  // console.log("props.pagination ==>", props.pagination)
  // config.data = props.defects.map((defect) => {
  //   return [defect[0], defect[1], defect[2]]
  // });
})
</script>

<style lang="scss">
.ant-pagination-item {
  background-color: #dddddd !important;
}

.ant-pagination-jump-prev .ant-pagination-item-container .ant-pagination-item-ellipsis,
.ant-pagination-jump-next .ant-pagination-item-container {
  background-color: #dddddd !important;
}

.ant-pagination-next {
  background-color: #dddddd !important;
}
</style>

<style lang="scss" scoped>
$box-height: 580px;
$box-width: 400px;

/* 将垂直滚动条改为深绿色系 */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background-color: #063447;
}

::-webkit-scrollbar-thumb {
  background-color: #04212F;
  border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: #04212F;
}



.centerRight2 {
  padding: 16px;
  padding-top: 20px;
  height: $box-height;
  width: $box-width;
  border-radius: 5px;


  .bg-color-black {
    height: $box-height - 70px;
    border-radius: 10px;


  }

  .text {
    color: #c3cbde;
  }

  .body-box {
    // border-radius: 10px;
    overflow-y: scroll;
    max-height: 480px;


    .date-cell {
      // background-color: pink;
    }


    .dv-scr-board {
      width: 370px;
      height: 490px;
    }

    ::v-deep .ant-table-wrapper {
      // background-color: yellow;
      width: 100%;
    }

    ::v-deep .ant-table-small {
      border-radius: 0px;
    }

    ::v-deep .ant-table-container {
      border-top-left-radius: 0px;
      border-top-right-radius: 0px;
    }

    ::v-deep .ant-table-thead {
      .ant-table-cell {
        background-color: #063447;
        color: #ffffff;
      }
    }

    ::v-deep .ant-table-tbody {
      .ant-table-cell {
        background-color: #04212F;
        color: #ffffff;
      }

      .ant-table-cell-row-hover {
        background-color: #063447;
        color: #ffffff;
      }
    }

    // ::v-deep .ant-table-body {
    //   ::-webkit-scrollbar {
    //     width: 12px;
    //     height: 12px;
    //   }

    //   ::-webkit-scrollbar-track {
    //     background-color: #063447;
    //   }

    //   ::-webkit-scrollbar-thumb {
    //     background-color: #04212F;
    //     border-radius: 6px;
    //   }

    //   ::-webkit-scrollbar-thumb:hover {
    //     background-color: #04212F;
    //   }
    // }
  }
}
</style>
